import React from 'react';
import './style.css';

import emitter from '../../util/events';

import AnchorEl from '../AnchorEl';
import AnchorItem from '../AnchorItem';
import SubmitButton from '../SubmitButton';
import ModalInit from '../../Modal/Ainit';

export default class Model extends React.Component {
	constructor(props){
		super(props)
		this.state = {
			AnchorEl: [
				{title: '基础信息',   id: 'base',        check: true},
				{title: '价格付款',   id: 'payment',     check: true},
				{title: '运输方式',   id: 'transport',   check: true},
				{title: '退款政策',   id: 'refundment',  check: true},
				{title: '产品识别码', id: 'IDcode',      check: true},
				{title: '产品属性',   id: 'attribute',   check: true},
				{title: '产品图片',   id: 'picture',     check: true},
				{title: '多属性信息', id: 'attrInfo',    check: true},
				{title: '多属性图片', id: 'attrPicture', check: true},
				{title: '产品描述',   id: 'depict',      check: true}
			],
			data: {}
		}
		this.handerData = this.handerData.bind(this);
	}

	handerData(data){
		if(!data.status) {
			return false;	
		}
		this.setState(state => {
			state.data = data.data;
		})
		emitter.emit('submitForm', this.state.data)
	}

	render(){
		return (
			<div>
				<div id="content">
					<AnchorItem AnchorEl={this.state.AnchorEl} onChange={this.handerData}/>
					<SubmitButton data={this.state}/>
				</div>
				<AnchorEl AnchorEl={this.state.AnchorEl}/>
				<ModalInit></ModalInit>
			</div>
		)
	}
}